$(document).ready(function () {
    var userstring = sessionStorage.getItem('user');
    var user = JSON.parse(userstring);
    var nickname=user.nickname;
    $('#nickname').text(nickname);
    const urlParams=new URLSearchParams(window.location.search);
    const id=urlParams.get('id');
    var image;
    var name;
    var price;
    var pageNum=1;
    var pageSize=10;
    $.get("food/show",{"id":id,"pageNum":pageNum,"pageSize":pageSize},function (rs) {
        var fs=rs.result.list;
        for (var i=0;i < fs.length;i++){
            image=fs[i].image;
            fname=fs[i].fname;
            price=fs[i].price;
            $("<img src='"+fs[i].image+"' style='height: 350px;width: 350px'>").appendTo("#imaid");
            var name = document.getElementById('strawberry-header');
            name.innerText=fs[i].fname;
            var remark = document.getElementById("remarkid");
            remark.innerText=fs[i].remark;
            $("<span class='show_pirze'>￥<em>"+fs[i].price+"</em></span>").appendTo(".prize_bar");
            $("<span class='show_unit'>单  位：500g</span>").appendTo(".prize_bar");
            var sumprice = document.getElementById("numberprice");
            sumprice.innerText=fs[i].price;
            var xiangqing = document.getElementById("shangpinid");
            xiangqing.innerText=fs[i].rec;
        }
    });
    $("[name='buynow']").click(function (){
        var quantity=$("#showadd").val();
        var amount=quantity * price;
        var fos=[{"quantity":quantity,"amount":amount,"image":image,"fname":fname,"price":price,"fid":id,"id":0}];
        var s = JSON.stringify(fos);
        sessionStorage.setItem("loc",s);
        window.location.href = "http://localhost:8080/place_order.html"
    });

    //点击下拉列表查询
    $(document).on("click","a[title=查询]",function () {
        var cid=$(this).attr("name");
        //点击下拉列表跳转界面带着id
        window.location.href = "http://localhost:8080/list.html?cid=" + cid;
    });

    //点击搜索按钮
    $(document).on("click","[name='shousuo']",function () {
        var likename=$("[name='likename']").val();
        window.location.href = "http://localhost:8080/list.html?fname=" + likename;
    })

});


